/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.
 */
package com.ce.pms.charge.dao.impl;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.InvalidPropertiesFormatException;
import java.util.List;
import java.util.Map;

import org.hibernate.Query;

import com.ce.pms.base.dao.impl.PmsBaseDaoImpl;
import com.ce.pms.charge.dao.IArCalculateDao;
import com.ce.pms.charge.model.AbstractTrans;
import com.ce.pms.charge.model.ArCalculateModel;
import com.ce.pms.charge.model.DebitTransDomain;
import com.ce.pms.charge.model.PeriodDomain;
import com.ce.pms.charge.vo.ArCalculateVO;
import com.ce.pms.charge.vo.SubAccountBean;
import com.ce.pms.common.annotation.AssociatedBuildingQuery;
import com.ce.pms.common.annotation.AssociatedPrecinctQuery;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.util.SqlConfig;
import com.sitechasia.webx.core.support.Page;



/**
 * 功能描述：应收计算<br>
 * @author 罗军林 创建日期：2008-8-27
 */
public class ArCalculateDaoImpl extends PmsBaseDaoImpl<AbstractTrans> implements IArCalculateDao {
	private static final String SQLFILENAME="ARCalculateSQL.xml";

	/**
	 * 常规费用配置文件的KEY
	 */
	private final String GENERAL_KEY="general";

	/**
	 * 固定费用配置文件的KEY
	 */
	private final String FIXED_KEY="fixed";

	/**
	 * 更新子帐户余额SQL KEY，参数为：费用,子帐户ID<br>
	 */
	private final String UPDATE_SUBACCOUNT_BALANCE="updateSubAccountBalance";

	/**
	 * 插入交易SQLKEY，参数为：房间ID，交易额，交易码ID，标准版本ID，子帐户ID，交易类型，交易状态，收费周期ID，操作人
	 */
	private final String INSERT_TRANSACTION="insertTransaction";

	/**
	 * 插入原始数据交易表，参数为：原始数据ID，交易ID
	 */
	private final String INSERT_DATAS_R_TRANSACTION="insertDatasTransaction";

	/**
	 * 更新原始数据的状态为已经计算，参数为：原始数据ID
	 */
	private final String UPDATE_DATAS_STATUS="updateDatasStatus";

	/**
	 * 查询帐户
	 */
	private final String QUERY_SUBACCOUNT="querySubAccount";

	/*
	 * 查询费用合计
	 */
	private final String QUERY_CHARGE_TOTAL_LIST="queryChargeTotalList";

	/**
	 * 更新是本金交易且未缴费的交易主交易ID为本记录ID，
	 */
	private final String UPDATE_M_TRANSID="updateMtransId";

	/**
	 * 走表费用配置文件的KEY
	 */
	private final String METER_KEY="meter";

	/**
	 * 更新帐户余额，这里为减去给定余额
	 */
	private final String UPDATE_SUBACCOUNT_BALANCE_SUB="updateSubAccountBalanceSub";

	/**
	 * 查询出要重算的交易记录
	 */
	private final String QUERY_RECALCULATE_TRAN="queryReCalculateTran";

	/**
	 * 统计指定交易ID里的同一帐户的总额
	 */
	private final String QUERY_SUM_DEBIT_BY_SUBACCOUNTID="querySumDebitBySubAccountId";

	/**
	 * 删除指定交易ID的交易记录
	 */
	private final String DELETE_TRANSACTION="deleteTransaction";

	/**
	 * 查询指定房号的常规费用
	 */
	private final String QUERY_GENERAL_BY_HOUSEIDS="queryGeneralByHouseIds";

	/**
	 * 查询指定房号的固定费用
	 */
	private final String QUERY_FIXEDS_BY_HOUSEIDS="queryFixedByHouseIds";

	/**
	 * 查询指定房号的走表费用
	 */
	private final String QUERY_METER_BY_HOUSEIDS="queryMeterByHouseIds";

	/**
	 * 删除指定交易记录与原始记录关系
	 */
	private final String DELETE_CHARGE_DATAS_R_TRANSACTION="deleteChargeDataSRTransaction";

	private SqlConfig sqlConfig=null;

	/**
	 * 当产生本实例的时候，就从配置文件中装载SQL到内存中
	 * @throws InvalidPropertiesFormatException
	 * @throws IOException
	 */
	public ArCalculateDaoImpl() throws InvalidPropertiesFormatException, IOException{
		sqlConfig=new SqlConfig(SQLFILENAME);
	}


	/**
	 * 功能描述:查询指定管理区指定楼栋下收费类型为常规费用的房间列表，包括房间的帐户、标准<br>
	 * 注：考虑到数据量的庞大性，为保证程序能相对稳定的运行，故进行分批查询<br>
	 * 结果集中为房间对象数组的LIST，对象数组的顺序为：房号ID，应收费用，交易码ID，版本ID，帐户ID<br>
	 * 此顺序与入帐操作comptabiliser有密切关系<br>
	 * @param periodDomain  当前收费周期
	 * @param buildingId	楼栋ID
	 * @param pageNO		页码
	 * @param pageSize		每次查询的记录数
	 * @return <br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-1<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	//@AssociatedBuildingQuery(alias = "H", beginStr = " AND ", endStr = " ", insertAfterPoint = "WHERE 2=2",property4Building="BUILDING_ID")
	public List<ArCalculateModel> getHouseListWithGeneral(PeriodDomain periodDomain,Long buildingId,int pageNO,int pageSize) {
		int startLine=(pageNO-1)*pageSize;
		Object[] parameters=new Object[]{
							periodDomain.getChargePrecinct().getKeyword(),
							buildingId,
							startLine,
							pageSize
							};
		Query query=this.createSQLQuery(sqlConfig.getSql(GENERAL_KEY), parameters);
		List<Object[]> list=query.list();

		return convertObjectArrayToDO(list);
	}


	/**
	 * 功能描述:查询指定管理区指定楼栋下收费类型为固定费用的房间列表，包括房间的帐户、标准<br>
	 * 注：考虑到数据量的庞大性，为保证程序能相对稳定的运行，故进行分批查询<br>
	 * 结果集中为房间对象数组的LIST，对象数组的顺序为：房号ID，应收费用，交易码ID，版本ID，帐户ID<br>
	 * 此顺序与入帐操作comptabiliser有密切关系<br>
	 * @param periodDomain  当前收费周期
	 * @param buildingId	楼栋ID
	 * @param pageNO		页码
	 * @param pageSize		每次查询的记录数
	 * @return <br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-1<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	//@AssociatedBuildingQuery(alias = "H", beginStr = " AND ", endStr = " ", insertAfterPoint = "WHERE 2=2",property4Building="BUILDING_ID")
	public List<ArCalculateModel> getHouseListWithFixed(PeriodDomain periodDomain,Long buildingId,int pageNO,int pageSize) {
		int startLine=(pageNO-1)*pageSize;
		Object[] parameters=new Object[]{
					periodDomain.getChargePrecinct().getKeyword(),
					buildingId,
					periodDomain.getStartDate(),
					periodDomain.getEndDate(),
					startLine,
					pageSize
					};

		Query query=this.createSQLQuery(sqlConfig.getSql(FIXED_KEY), parameters);
		List<Object[]> list=query.list();

		return convertObjectArrayToDO(list);
	}

	/**
	 * 功能描述:查询指定管理区指定楼栋下收费类型为走表费用的房间列表，包括房间的帐户、标准<br>
	 * 注：考虑到数据量的庞大性，为保证程序能相对稳定的运行，故进行分批查询<br>
	 * 结果集中为房间对象数组的LIST，对象数组的顺序为：房号ID，版本ID，走表数据量，交易码ID，走表ID，原始数据ID列表(用逗号隔开)，帐户ID<br>
	 * 此顺序与入帐操作comptabiliser有密切关系<br>
	 * @param periodDomain  当前收费周期
	 * @param buildingId	楼栋ID
	 * @param pageNO		页码
	 * @param pageSize		每次查询的记录数
	 * @return <br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-1<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	//@AssociatedBuildingQuery(alias = "H", beginStr = " AND ", endStr = " ", insertAfterPoint = "WHERE 2=2",property4Building="BUILDING_ID")
	public List<ArCalculateModel> getHouseListWithMeter(PeriodDomain periodDomain, Long buildingId, int pageNO,int pageSize) {
		int startLine=(pageNO-1)*pageSize;
		Object[] parameters=new Object[]{
					periodDomain.getChargePrecinct().getKeyword(),
					buildingId,
					startLine,
					pageSize
					};

		Query query=this.createSQLQuery(sqlConfig.getSql(METER_KEY), parameters);
		List<Object[]> list= query.list();

		return convertObjectArrayMeterDo(list);
	}

	/**
	 * 功能描述:读取满足应收计算条件的收费周期；<br>
	 * 收费周期与收费管理区一一对应，(用户有权限做应收计算，且未做应收计算的所有管理区)<br>
	 * <br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-29<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	@SuppressWarnings("unchecked")
	@AssociatedPrecinctQuery(alias="p", beginStr=" AND ", endStr=" ", insertAfterPoint="WHERE 1=1",property4Precinct="chargePrecinct.keyword")
	public List<PeriodDomain> getPeriodList() {
		Query query=this.createQuery(sqlConfig.getSql("prechinctListHQL"), null);
		return query.list();
	}


	/**
	 * 功能描述:<br>
	 * @param sqlKey
	 * @param parameters
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-3<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public List<Object[]> querySQL(String sqlKey, Object[] parameters) {
		Query query=createSQLQuery(sqlConfig.getSql(sqlKey), parameters);
		return query.list();
	}

	/**
	 * 功能描述:<br>
	 * @param parameterList<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-3<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void insertTransaction(List<Object[]> parameterList) {
		executeSQLBatch(sqlConfig.getSql(INSERT_TRANSACTION), parameterList);
	}

	/**
	 * 功能描述:批量更新帐户余额<br>
	 * @param parameterList<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-3<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void updateSubAccountBalance(List<Object[]> parameterList) {
		executeSQLBatch(sqlConfig.getSql(UPDATE_SUBACCOUNT_BALANCE), parameterList);
	}

	/**
	 * 功能描述:批量增加原始数据-交易关系表<br>
	 * @param parameterList<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-4<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void addBatchDatasRTransaction(List<Object[]> parameterList){
		executeSQLBatch(sqlConfig.getSql(INSERT_DATAS_R_TRANSACTION), parameterList);
	}

	/**
	 * 功能描述:批量更新原始数据状态为已经计算<br>
	 * @param parameterList 原始数据ID列表<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-4<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void updateBatchDatasStatus(List<Object[]> parameterList){
		executeSQLBatch(sqlConfig.getSql(UPDATE_DATAS_STATUS), parameterList);
	}

	/**
	 * 功能描述:查询指定管理区下的所有子帐户<br>
	 * @param chargePrecinctId
	 * <br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public Map<Long,SubAccountBean> querySubaccount(Long chargePrecinctId){
		Query query=createSQLQuery(sqlConfig.getSql(QUERY_SUBACCOUNT), chargePrecinctId);
		List<Object[]> list=query.list();
		Map<Long, SubAccountBean> result=new HashMap<Long, SubAccountBean>();
		for(Object[] subAccount : list){
			SubAccountBean subAccountBean =new SubAccountBean();
			subAccountBean.setHouseId(((BigInteger)subAccount[0]).longValue());
			subAccountBean.setSubAccountId(((BigInteger)subAccount[1]).longValue());
			subAccountBean.setLockState((String)subAccount[2]);

			result.put( subAccountBean.getHouseId(), subAccountBean);
		}
		return result;
	}


	/**
	 * 功能描述:查询交易记录<br>
	 * @param searchCondition
	 * <br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	//@AssociatedBuildingQuery(alias = "dtr", beginStr = " AND ", endStr = " ", insertAfterPoint = " WHERE 1=1",property4Building="house.building.keyword")
	@AssociatedPrecinctQuery(alias = "dtr", beginStr = " AND ", endStr = " ", insertAfterPoint = "WHERE 1=1" ,property4Precinct="period.chargePrecinct.keyword")
	public Page queryDebitTrans(ArCalculateVO searchCondition){
		Map<String, Object> paremeter=new HashMap<String, Object>();
		StringBuffer hql=new StringBuffer();
		hql.append("FROM DebitTransDomain dtr WHERE 1=1 ");
		hql.append(buildCondition(searchCondition, paremeter));

		Page page=this.pagedNameQueryByPageNo(hql.toString(), searchCondition.getPageNo(), searchCondition.getPageSize(), paremeter);
		return page;
	}

	/**
	 * 功能描述:查询交易合计<br>
	 * @param searchCondition<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	@AssociatedPrecinctQuery(alias="per", beginStr=" AND ", endStr=" ", insertAfterPoint="WHERE 2=2",property4Precinct="CHARGE_PRECINCT_ID")
	public Page queryChargeTotalList(ArCalculateVO searchCondition){
		List paremeter=new ArrayList();
		String sql=sqlConfig.getSql(QUERY_CHARGE_TOTAL_LIST);
		sql=sql.replaceAll("_searchCondtion", buildSqlCondition(searchCondition,paremeter));
		Page page=this.pagedSqlQueryByPageNo(sql, searchCondition.getPageNo(), searchCondition.getPageSize(), paremeter.toArray());
		page.setResult(convertObjectArrayChargeTotal(page));
		return page;
	}

	/**
	 * 功能描述:更新是本金交易且未缴费的主交易ID为本记录主键<br>
	 * <br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void updateMtranId(){
		executeSQL(sqlConfig.getSql(UPDATE_M_TRANSID),null);
	}

	/**
	 * 功能描述:查询出要重算的交易记录。交易ID串，以逗号隔开<br>
	 * @param houseIds 房号ID列表，用','隔开
	 * @param chargetype 费用类型
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	@AssociatedBuildingQuery(alias = "H", beginStr = " AND ", endStr = " ", insertAfterPoint = "WHERE 2=2",property4Building="BUILDING_ID")
	public String queryReCalculateTran(String houseIds, Long periodId,String chargetype){
		String sql=sqlConfig.getSql(QUERY_RECALCULATE_TRAN).replaceAll("_hids", houseIds);
		Query query=createSQLQuery(sql, chargetype,periodId);
		List<BigInteger> list=query.list();

		StringBuffer result=new StringBuffer();
		for(BigInteger tranId : list){
			result.append( tranId ).append(',');
		}
		if( result.lastIndexOf(",") >0){
			result.deleteCharAt(result.length()-1);
		}
		return result.toString();
	}

	/**
	 * 功能描述:查询出要重算的交易记录。返回map,主键为子帐户ID，值为费用总和<br>
	 * @param houseIds 房号ID列表，用','隔开
	 * @param chargetype 费用类型
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public Map<Long,BigDecimal> querySumDebitBySubAccountId(Long periodId, String tranIds){
		String sql=sqlConfig.getSql(QUERY_SUM_DEBIT_BY_SUBACCOUNTID).replaceAll("_tranids", tranIds);
		Query query=createSQLQuery(sql,periodId);
		List<Object[]> list=query.list();

		Map<Long,BigDecimal> result=new HashMap<Long, BigDecimal>();
		for(Object[] item : list){
			result.put( ((BigInteger)item[0]).longValue(), (BigDecimal)item[1]);
		}
		return result;

	}

	/**
	 * 功能描述:更新帐户余额，这里为减去给定余额<br>
	 * @param parameterList Object[]中的内容为：要减去的余额,子帐户ID
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void updateSubAccountBalanceSub(List<Object[]> parameterList){
		executeSQLBatch(sqlConfig.getSql(UPDATE_SUBACCOUNT_BALANCE_SUB), parameterList);
	}

	/**
	 * 功能描述:删除交易记录<br>
	 * @param parameterList<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-12<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void deleteTransaction(Long periodId,String tranIds){
		String sql=sqlConfig.getSql(DELETE_TRANSACTION).replaceAll("_tranids", tranIds);
		executeSQL(sql, new Object[]{periodId});
	}

	/**
	 * 功能描述:删除交易与原始数据关系表记录<br>
	 * @param parameterList<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-12<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void deleteDataSRTransaction(String tranIds){
		String sql=sqlConfig.getSql(DELETE_CHARGE_DATAS_R_TRANSACTION).replaceAll("_tranids", tranIds);
		executeSQL(sql, null);
	}

	@AssociatedBuildingQuery(alias = "H", beginStr = " AND ", endStr = " ", insertAfterPoint = "WHERE 2=2",property4Building="BUILDING_ID")
	public List<ArCalculateModel> queryGeneralByHouseIds(String houseIds,Long periodId){
		String sql=sqlConfig.getSql(QUERY_GENERAL_BY_HOUSEIDS).replaceAll("_hids", houseIds);
		Query query=createSQLQuery(sql,periodId);
		return convertObjectArrayToDO(query.list());
	}

	@AssociatedBuildingQuery(alias = "H", beginStr = " AND ", endStr = " ", insertAfterPoint = "WHERE 2=2",property4Building="BUILDING_ID")
	public List<ArCalculateModel> queryFixedByHouseIds(String houseIds,Long periodId){
		String sql=sqlConfig.getSql(QUERY_FIXEDS_BY_HOUSEIDS).replaceAll("_hids", houseIds);
		Query query=createSQLQuery(sql, periodId);
		return convertObjectArrayToDO(query.list());
	}

	@AssociatedPrecinctQuery(alias = "P", beginStr = " AND ", endStr = " ", insertAfterPoint = "WHERE 2=2",property4Precinct="CHARGE_PRECINCT_ID")
	public List<ArCalculateModel> queryMeterByHouseIds(String houseIds,Long periodId){
		String sql=sqlConfig.getSql(QUERY_METER_BY_HOUSEIDS).replaceAll("_hids", houseIds);
		Query query=createSQLQuery(sql, periodId);
		return convertObjectArrayMeterDo(query.list());
	}

	/**
	 * 功能描述:查找指定原始数据ID的交易<br>
	 * @param datasId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-10-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public DebitTransDomain findDebitTransByChargeDatasId(Long datasId){
		String hql="FROM DebitTransDomain dt where dt.chargeDatas.chargeDataId=?";
		Query query=createQuery(hql, datasId);
		return (DebitTransDomain)query.uniqueResult();
	}

	/** 功能描述:<br>
	 * @param page
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private List<ArCalculateVO> convertObjectArrayChargeTotal(Page page) {
		List<Object[]> result=page.getResult();

		List<ArCalculateVO> tempList=new ArrayList<ArCalculateVO>();
		for(Object[] item : result){
			ArCalculateVO arCalculateVO=new ArCalculateVO();
			arCalculateVO.setPeriodName(String.valueOf(item[0]));
			arCalculateVO.setBuildingName(String.valueOf(item[1]));
			arCalculateVO.setHouseNumber(String.valueOf(item[2]));
			arCalculateVO.setGeneralAmt((BigDecimal)item[3]);
			arCalculateVO.setMeterAmt((BigDecimal)item[4]);
			arCalculateVO.setOtherAmt((BigDecimal)item[5]);
			BigDecimal amt=addBigDecimal(arCalculateVO.getOtherAmt(),
					addBigDecimal(arCalculateVO.getGeneralAmt(),arCalculateVO.getMeterAmt()));
			arCalculateVO.setAmt(amt);
			arCalculateVO.setHouseId(((BigInteger)item[7]).longValue());
			tempList.add(arCalculateVO);
		}
		return tempList;
	}

	/**
	 * 功能描述:返回两数的和，如果有一项为NULL，则直接返回另一项<br>
	 * @param a
	 * @param b
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-24<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private BigDecimal addBigDecimal(BigDecimal a,BigDecimal b){
		if(null==a){
			return b;
		}else if(null==b){
			return a;
		}else{
			return a.add(b);
		}
	}


	/**
	 * 功能描述:费用合计查询条件的构造<br>
	 * @param searchCondition
	 * @param paremeter
	 * @param hql<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private String buildSqlCondition(ArCalculateVO searchCondition,List paremeter) {
		StringBuffer hql=new StringBuffer();
		if(null != searchCondition.getBuildingId()){
			hql.append(" AND hb.BUILDING_ID=?");
			paremeter.add(searchCondition.getBuildingId());
		}
		if(null != searchCondition.getHouseNumber() && searchCondition.getHouseNumber().trim().length()>0){
			hql.append(" AND hm.HOUSE_NUMBER like ?");
			paremeter.add("%"+searchCondition.getHouseNumber()+"%");
		}
		if(null != searchCondition.getPeriodId()){
			hql.append(" AND per.PERIOD_ID=?");
			paremeter.add(searchCondition.getPeriodId());
		}
		return hql.toString();
	}


	/**
	 * 功能描述:<br>
	 * @param searchCondition
	 * @param paremeter
	 * @param hql<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private String buildCondition(ArCalculateVO searchCondition, Map<String, Object> paremeter) {
		StringBuffer hql=new StringBuffer();
		if(null != searchCondition.getChrgType()){
			if("other".equals(searchCondition.getChrgType())){
				hql.append(" AND dtr.staVersion.chargeSta.chargeItem.chrgType in (")
				.append(SysrefcodeDO.FEE_CHAR_TYPE_CLASS_CODE_FIXED)
				.append(",")
				.append(SysrefcodeDO.FEE_CHAR_TYPE_CLASS_CODE_OTHER)
				.append(") ");
//				paremeter.put("chrgType1", SysrefcodeDO.FEE_CHAR_TYPE_CLASS_CODE_FIXED);
//				hql.append(" AND dtr.staVersion.chargeSta.chargeItem.chrgType=:chrgType2 ");
//				paremeter.put("chrgType2", SysrefcodeDO.FEE_CHAR_TYPE_CLASS_CODE_OTHER);
			}else{
				hql.append(" AND dtr.staVersion.chargeSta.chargeItem.chrgType=:chrgType ");
				paremeter.put("chrgType", searchCondition.getChrgType());
			}
		}
		if(null != searchCondition.getBuildingId()){
			hql.append(" AND dtr.house.building.keyword=:buildingId");
			paremeter.put("buildingId", searchCondition.getBuildingId());
		}

		if(null != searchCondition.getHouseNumber() && searchCondition.getHouseNumber().trim().length()>0){
			hql.append(" AND dtr.house.houseNumber like :houseNumber");
			paremeter.put("houseNumber", "%"+searchCondition.getHouseNumber()+"%");
		}

		if(null != searchCondition.getChargeItemId()){
			hql.append(" AND dtr.staVersion.chargeSta.chargeItem.keyword=:chargeStaId");
			paremeter.put("chargeStaId", searchCondition.getChargeItemId());
		}

		if(null != searchCondition.getPeriodId()){
			hql.append(" AND dtr.period.keyword=:periodId");
			paremeter.put("periodId", searchCondition.getPeriodId());
		}
		return hql.toString();
	}

	/**
	 * 功能描述:将查出来的常规、固定费用对象数组转换成一个实体对象<br>
	 * @param list
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-10<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private List<ArCalculateModel> convertObjectArrayToDO(List<Object[]> list) {
		List<ArCalculateModel> arCalculateList=new ArrayList<ArCalculateModel>();
		for(Object[] houseItem : list){
			ArCalculateModel arcalculateModel=new ArCalculateModel();
			arcalculateModel.setHouseId( ((BigInteger)houseItem[0]).longValue() );
			arcalculateModel.setAmt( (BigDecimal)houseItem[1] );
			arcalculateModel.setBizCodeId( ((BigInteger)houseItem[2]).longValue() );
			arcalculateModel.setChargeStaVerionId( ((BigInteger)houseItem[3]).longValue() );
			if(houseItem.length>4){
				arcalculateModel.setSubAccountId( ((BigInteger)houseItem[4]).longValue() );
			}
			if(houseItem.length>5){
				arcalculateModel.setPeriodId( ((BigInteger)houseItem[5]).longValue() );
			}
			arCalculateList.add(arcalculateModel);
		}
		return arCalculateList;
	}

	/**
	 * 功能描述:将查出来的走表类型的对象数组转换成实体对象<br>
	 * @param list
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-10<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private List<ArCalculateModel> convertObjectArrayMeterDo(List<Object[]> list) {
		List<ArCalculateModel> arCalculateList=new ArrayList<ArCalculateModel>();
		for(Object[] houseItem : list){
			ArCalculateModel arcalculateModel=new ArCalculateModel();
			arcalculateModel.setHouseId( ((BigInteger)houseItem[0]).longValue() );
			arcalculateModel.setChargeStaVerionId( ((BigInteger)houseItem[1]).longValue() );
			arcalculateModel.setWastage( (BigDecimal)houseItem[2] );
			arcalculateModel.setBizCodeId( ((BigInteger)houseItem[3]).longValue() );
			arcalculateModel.setMeterId( ((BigInteger)houseItem[4]).longValue() );
			arcalculateModel.setChargeDatasIds( String.valueOf(houseItem[5]) );
			if(houseItem.length>6){
				arcalculateModel.setSubAccountId( ((BigInteger)houseItem[6]).longValue() );
			}
			if(houseItem.length>7){
				arcalculateModel.setPeriodId( ((BigInteger)houseItem[7]).longValue() );
			}
			arCalculateList.add(arcalculateModel);
		}
		return arCalculateList;
	}


}

